package com.ui.cases;

import com.ui.base.Base;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class RegisterCase2 extends Base {
    /*失败测试用例，手机号为空*/
    //下方没有提供时，默认使用方法名称
    @Test(dataProvider = "failCaseDatas")
    public void failCase1(String mobilepone,String pwd,String confirmPwd,String expectedMsg){
        driver.navigate().to("http://39.108.136.60:8085/lmcanon_web_auto/mng/register.html");
        driver.findElement(By.id("mobilephone")).sendKeys(mobilepone);
        driver.findElement(By.id("password")).sendKeys(pwd);
        driver.findElement(By.id("pwdconfirm")).sendKeys(confirmPwd);
        driver.findElement(By.id("signup-button")).click();
        String errorMsg=driver.findElement(By.className("tips")).getText();
        Assert.assertEquals(errorMsg,expectedMsg);
    }
    @Test(dataProvider = "successCaseDatas")
    public void successCase(String mobilepone,String pwd,String confirmPwd){
        driver.navigate().to("http://39.108.136.60:8085/lmcanon_web_auto/mng/register.html");
        driver.findElement(By.id("mobilephone")).sendKeys(mobilepone);
        driver.findElement(By.id("password")).sendKeys(pwd);
        driver.findElement(By.id("pwdconfirm")).sendKeys(confirmPwd);
        driver.findElement(By.id("signup-button")).click();
        //显示等待，拿到登录界面的url
        boolean flag = urlPresenceContent("login.html");
        //String currentUrl = driver.getCurrentUrl();
        Assert.assertTrue(flag);
    }
    @DataProvider
    public Object[][] failCaseDatas() {
        Object[][] datas = {
                //二维数组每个元素是一个一维数组
                {"", "", "","用户名不能为空"},
                {"aa", "", "","非法的手机号"},
                {"18311447530", "", "","密码不能为空"},
                {"18311447530", "12345", "","密码长度至少为6位"},
                {"18311447530", "123456", "","重复密码不能为空"},
                {"18311447530", "123456", "12345678","密码不一致"},

        };
        return datas;
    }
    @DataProvider
    public Object[][] successCaseDatas() {
        Object[][] datas = {
                //二维数组每个元素是一个一维数组
                {"18311447532", "123456", "123456"},
        };
       return datas;
}

}
